var cflag = false;
var tag = "";
$().ready(function(){
	$(".addshare").click(function(){
		var url = $(this).attr("href");
		$.get(url,{ajax:1},function(data){
			//actionMessage($(".addshare"),data);
			$.facebox(data);
			$("#sharedesc").focus();
			$("#saveshare").bind("click",function(){
				$(this).attr("disabled", "disabled");
				$.post(APP+"/share/saveshare",{ajax:1 , sharedesc:$("#sharedesc").val() , g:$(this).prev().prev().val() , moduleid:$(this).prev().val() , url:$("#shareurl").val() },
					function(data){
						if("success" == data){
							msg($("#saveshare"),"分享成功");
							$("#actionMessageBox").fadeOut(3000);
						}else{
							msg($("#saveshare"),"操作失败,你可以重试");
						}
					}
				)
			});
		});
		return false;
	});
	//jQuery('a[rel*=facebox]').facebox();
	$("#searchname").focus(function(){  
		if("输入人名" == $(this).val()){$(this).val("")};}).blur(function(){ 
			if("" == $(this).val()){
				$(this).val("输入人名");
			}
	});
	
	$(".drop").each(function(){
		$(this).hover(function(){
			tag = $(this).attr("tag");
			var _top = ($(this).offset().top+18) +"px";
			var _left = ($(this).offset().left-33) + "px";
			var pobj = $(this).prev();
			$(pobj).addClass("hiddenum_hover");
			$("#"+tag).css("visibility","visible");
			$("#"+tag).css("top",_top);
			$("#"+tag).css("left",_left);
			$("#"+tag).css("z-index",2);
			$("#"+tag).hover(function(){
				$(pobj).addClass("hiddenum_hover");
				$("#"+tag).css("visibility","visible");
			},
			function(){
				$(pobj).removeClass("hiddenum_hover");
				$("#"+tag).css("visibility","hidden");
			}); 
		},
		function(){
			$(this).prev().removeClass("hiddenum_hover");
			$("#"+tag).css("visibility","hidden");
		}); 
	});
	$(".feeddel").each(function(){
		$(this).click(function(){
			alertMessage(this,"确定删除这条记录");
			var obj  = this;
			$(".msgOk").bind("click",function(){affirm2(obj);});
			return false;
		});
	});
	$("#findfriend").click(
		function(){
			$(this).parent().parent().parent().css("visibility","hidden");
			$("#searchname").focus();
			return false;
		}
	);
		
})

function check(obj){
	var url = $(obj).attr("href");
	$.get(url,{ajax:1},function(data){
		actionMessage(obj,data);
	})
	return false;
}

function affirm2(obj){
	$("#messageBox").remove();
	var url = $(obj).attr("href");
	$.get(url,{ajax:1},function(data){
		if("success" == data){
			$(obj).parent().fadeOut(3000);
		}else{
			msg(obj,"操作失败，你可以重试");
			//$(obj).parent().parent().slideUp();
		}
	})
	return false;
}

function affirm(obj){
	var url = $(obj).attr("href");
	$.get(url,{ajax:1},function(data){
		if("success" == data){
			msg(obj,"操作成功");
			$(obj).parent().fadeOut("slow");
			var numobj =  $("#"+$(obj).attr("title"));
			var num = parseInt($(numobj).text());
			num--;
			if(num==0){
				$(numobj).parent().parent().slideUp();
			}else{
				$(numobj).text(num);
			}
			$(obj).parent().parent().fadeOut(2000);
		}else if("successfriend"==data){
			var friendname = $(obj).parent().prev(">span").html();
			$(obj).parent().parent().html("你和"+friendname+"成为了好友");
		}else{
			msg(obj,"操作失败，你可以重试");
			//$(obj).parent().parent().slideUp();
		}
	})
	return false;
}

function alertMessage(obj,message){
	if($("#messageBox").attr("id") == "messageBox"){
		$("#messageBox").remove();
	}
	var div_box = document.createElement("DIV");
	div_box.id = "messageBox";
	div_box.style.position ="absolute";
	div_box.style.width = "220px";
	div_box.style.height = "90px";
	div_box.style.background = "#f8f8f8";
	div_box.style.border = "1px solid #666";
	div_box.style.top = ($(obj).offset().top-95) +"px";
	div_box.style.left = ($(obj).offset().left-120) +"px";
	div_box.style.zIndex = "1000";
	//var content =  '<iframe src="about:blank" frameBorder=0 width="100%" height="0" scrolling=no style="border:1px #0000FF solid;"></iframe>';
	var content = '<p style="margin:0px;font-size:14px;font-weight: bold;padding-left: 10px;padding-top:10px;text-align: left;">';
	content += message+'</p><p style="padding-right: 10px;text-align: right;"><input type="button" class="msgOk" value="确定"/>  <input type="button" class="msgCancel" value="取消"/></p>';
	div_box.innerHTML = content;
	document.body.appendChild(div_box);
	//$("#messageBox").fadeOut(10000);
	$(".msgCancel").bind("click",function(){$("#messageBox").remove();});
}

function floatMessage(obj,message){
	if($("#floatMessageBox").attr("id") == "floatMessageBox"){
		$("#floatMessageBox").remove();
	}
	var div_box = document.createElement("DIV");
	div_box.id = "floatMessageBox";
	div_box.style.position ="absolute";
	div_box.style.width = "300px";
	div_box.style.height = "80px";
	div_box.style.background = "#f8f8f8";
	div_box.style.border = "1px solid #666";
	div_box.style.top = ($(obj).offset().top-85) +"px";
	div_box.style.left = ($(obj).offset().left-120) +"px";
	div_box.style.zIndex = "1000";
	//var content =  '<iframe src="about:blank" frameBorder=0 width="100%" height="0" scrolling=no style="border:1px #0000FF solid;"></iframe>';
	var content = '<p style="margin:0px;font-size:12px;padding:10px;text-align: left;">';
	content += message+'</p>';
	div_box.innerHTML = content;
	document.body.appendChild(div_box);
	//$("#floatMessageBox").fadeOut(10000);
}

function actionMessage(obj,message){
	if($("#actionMessageBox").attr("id") == "actionMessageBox"){
		$("#actionMessageBox").remove();
	}
	var div_box = document.createElement("DIV");
	div_box.id = "actionMessageBox";
	div_box.style.position ="absolute";
	div_box.style.width = "400px";
	if($(obj).offset().top>500){
		div_box.style.top = ($(obj).offset().top-500) +"px";
	}else{
		div_box.style.top = ($(obj).offset().top-10) +"px";
	}
	//div_box.style.top = "200px";
	div_box.style.left = ($(obj).offset().left-480) +"px";
	//div_box.style.margin = "auto";
	div_box.style.zIndex = "1000";
	//var content =  '<iframe src="about:blank" frameBorder=0 width="100%" height="0" scrolling=no style="border:1px #0000FF solid;"></iframe>';
	var content = '<p style="margin:0px;font-size:14px;font-weight: bold;padding:0px;text-align: left;">';
	content += message+'</p><p style="clear:both;padding-right: 10px;text-align: right;"><input type="button" class="msgCancel" value="关闭窗口"/></p>';
	div_box.innerHTML = content;
	document.body.appendChild(div_box);
	$(".msgCancel").bind("click",function(){$("#actionMessageBox").remove();});
}

function msg(obj,data){
	$(obj).after(' <span id="msg_span" class="over">'+data+'</span>');
	$("#msg_span").fadeOut(2000,function(){ $("#msg_span").remove(); });

}

function del(obj){
	alertMessage(obj,"确定删除");
	$(".msgOk").bind("click",function(){delaction(obj);});
}

function delaction(obj){
	//alert($(obj).attr("id")+$(obj).attr("title"));
	$.get(APP + "/user/delmini" , {id:$(obj).attr("id"),ajax:1} ,
		function (data){
			if("success" == data){
				$("#messageBox").remove();
				$(obj).parent().parent().parent().fadeOut(2000);
			}else{
				$("#messageBox").remove();
				msg(obj,"操作失败");
			}
		}
	)
}

function delBlog(obj){
	alertMessage(obj,"确定删除");
	$(".msgOk").bind("click",function(){delBlogAction(obj);});
}

function delBlogAction(obj){
	location.href = APP + '/blog/deleteblog/id/' + ($(obj).attr("title"));
}